package com.edu.processer;

import com.edu.handler.Loghandler;
import com.edu.interceptor.LogInterceptor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.stereotype.Component;

import java.lang.reflect.Proxy;

@Component
public class LogProcesser implements BeanPostProcessor {
//    @Override
//    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
//        Object o = Proxy.newProxyInstance(bean.getClass().getClassLoader(), bean.getClass().getInterfaces(), new Loghandler(bean));
//        System.out.println();
//        return o;
//    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        Object o = Enhancer.create(bean.getClass(),new LogInterceptor(bean));
        return o;
    }
}
